<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function breathe(amount){
            return new Promise((resolve,reject)=>{
                if(amount<500){
                    reject('that is too small of a value');
                }
                setTimeout(() => resolve(`Done for ${amount} ms`),amount);
            })
        }
        async function go(name,last){
            console.log(name,last);
            const res = await breathe(1000);
            console.log(res)
            const res3=await breathe(750);
            console.log(res3);
            const res2 = await breathe(300);
            console.log(res2);
            const res4= await breathe(900);
            console.log(res4);
        }
        // 高阶函数
        function catchErrors(fn){
            console.log(fn,'111');
            // args=arguments;
            return function(...args){
                // console.log(...args,'222')
                return fn(...args).catch(err=>{
                    console.log(err);
                });
            }
        }
        const wrappedFunction = catchErrors(go);
        wrappedFunction('wes','Bos');
        // breathe(600)
        // .then(data=>{
        //     console.log(data);
        // })
        // .catch(err=>{
        //     console.log(err);
        // });
    </script>
</body>
</html>